﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Xml;
using System.Xml.Serialization;

namespace Futajma.MigrationStudio.DataDefinition
{
    [ObfuscationAttribute(Exclude = true, ApplyToMembers = true)]
    public class ProjectParameter
    {
        public void ResetProject()
        {
            SelectedSharePointItemId = ProjectVersion = 0;
            ProjectIsCommited = false;
        }

        public int SelectedSharePointItemId { get; set; }

        public int ProjectVersion { get; set; }

        public bool ProjectIsCommited { get; set; }

        public string ProjectName { get; set; }

        public static ProjectParameter LoadXml(Stream stream)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(ProjectParameter));
            var projectParameter = (ProjectParameter)(serializer.Deserialize(stream));
            return projectParameter;
        }

        public static StringBuilder Save(ProjectParameter projectParameter)
        {
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Encoding = new UnicodeEncoding(false, false);
            settings.Indent = true;
            //settings.CheckCharacters = false;
            settings.OmitXmlDeclaration = true;

            var serializer = new XmlSerializer(typeof(ProjectParameter));
            StringBuilder sb = new StringBuilder();
            using (XmlWriter writer = XmlWriter.Create(sb, settings))
            {
                serializer.Serialize(writer, projectParameter);
            }
            return sb;
        }
    }
}
